<template>
     <div v-if="rateSettingStatus" class="m-detail-modal">
    <div class="header">
            车商费率设置
            <span @click="close"><Icon type="close-round"></Icon></span>
        </div>
        <br>
        <div class="content">
            <div class="car-header" style="font-size: 18px">费率设置</div>
                  <div class="m-modal-content-header" v-if="displayede">
                       <i-switch v-model="switchStatus" size="large" style="float: right" @on-change="changeRateStatus">
                           <span slot="open">开启</span>
                           <span slot="close">关闭</span>
                       </i-switch>
                   </div>


                <Form>
                <!--<div class="car-header"style="font-size: 14px;width: 300px">等级  </div>-->
                <FormItem  label="等级:" style="font-size: 26px">

                    <Select v-model="dealer_grade.dealer_grade_id" placeholder="请选择等级" style="width: 250px" @on-change="getGradeName">
                        <Option :value="item.id" v-for="item in gradeData" :key="item.grade_name">
                            {{item.grade_name}}
                        </Option>
                    </Select>
                    <span style="color: red;font-size: 16px">{{defaultGradeText}}</span>
                </FormItem>
                </Form>
            <Row>
                <Col span="24">
                <Card>
                    <Row>
                        <div class="car-header">储蓄卡</div>
                        <table>
                            <thead>
                            <tr>
                                <th>配置时间</th>
                                <th>结算时间</th>
                                <th>结算费率</th>
                                <th>最高收费</th>
                                
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>常规时间</td>
                                <td>
                                    <Select v-model="dataList[0].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName0">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[0].close_rate" size="small" style="width: 100%" type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[0].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                                
                            </tr>
                            <tr>
                                <td>
                                    从<DatePicker :value="dataList[1].start_time" @on-change="initStartTime1" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                    到<DatePicker :value="dataList[1].end_time" @on-change="initEndTime1" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                </td>
                                <td>
                                    <Select v-model="dataList[1].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName1">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[1].close_rate" size="small" style="width: 100%" type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[1].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </Row>
                </Card>
                </Col>
                <Col span="24">
                <Card>
                    <Row>
                        <div class="car-header">信用卡</div>
                        <table>
                            <thead>
                            <tr>
                                <th>配置时间</th>
                                <th>结算时间</th>
                                <th>结算费率</th>
                                <th>最高收费</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>常规时间</td>
                                <td>
                                    <Select v-model="dataList[2].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName2">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[2].close_rate" size="small" style="width:100%"  type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[2].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    从<DatePicker :value="dataList[3].start_time" @on-change="initStartTime2" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                    到<DatePicker :value="dataList[3].end_time" @on-change="initEndTime2" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                </td>
                                <td>
                                    <Select v-model="dataList[3].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName3">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[3].close_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[3].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </Row>
                </Card>
                </Col>

            </Row>

            <Row>
                <Col span="24">

                <Card>
                    <Row>
                        <div class="car-header">微信</div>
                        <table>
                            <thead>
                            <tr>
                                <th>配置时间</th>
                                <th>结算时间</th>
                                <th>结算费率</th>
                                <th>最高收费</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>常规时间</td>
                                <td>
                                    <Select v-model="dataList[4].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName4">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[4].close_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[4].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    从<DatePicker :value="dataList[5].start_time" @on-change="initStartTime3" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                    到<DatePicker :value="dataList[5].end_time" @on-change="initEndTime3" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                </td>
                                <td>
                                    <Select v-model="dataList[5].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName5">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[5].close_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[5].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </Row>
                </Card>
                </Col>
                <Col span="24">
                <Card>
                    <Row>
                        <div class="car-header">支付宝</div>
                        <table>
                            <thead>
                            <tr>
                                <th>配置时间</th>
                                <th>结算时间</th>
                                <th>结算费率</th>
                                <th>最高收费</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>常规时间</td>
                                <td>
                                    <Select v-model="dataList[6].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName6">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[6].close_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[6].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    从<DatePicker :value="dataList[7].start_time" @on-change="initStartTime4" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                    到<DatePicker :value="dataList[7].end_time" @on-change="initEndTime4" size="small" type="date" placeholder="选择日期" style="width: 120px"></DatePicker>
                                </td>
                                <td>
                                    <Select v-model="dataList[7].close_id" size="small" style="width:100%" @on-change="getsettlement_wayName7">
                                        <Option :value="item.settlement_way_id" v-for="item in settlement_wayList" :key="item.settlement_way_name">
                                            {{item.settlement_way_name}}
                                        </Option>
                                    </Select>
                                </td>
                                <td>
                                    <Input v-model="dataList[7].close_rate" size="small" style="width: 100%" type="text">
                                    <span slot="append">‰</span>
                                    </Input>
                                </td>
                                <td>
                                    <Input v-model="dataList[7].max_money" size="small" style="width: 100%" type="text">
                                    <span slot="append">元</span>
                                    </Input>
                                </td>
                            </tr>
                            </tbody>
                        </table>
                    </Row>
                </Card>
                </Col>

            </Row>

            </div>
            <div class="m-modal-footer">
                <Button type="primary" @click="submitFn" style="width: 80px">提交</Button>
            </div>


           <div class="content">
               <div class="car-header" style="font-size: 18px">返还配置</div>
               <div class="m-modal-content-header" v-if="displayedeReturn">
                   <i-switch v-model="switchReturnStatus" size="large" style="float: right" @on-change="changeReturnStatus">
                       <span slot="open">开启</span>
                       <span slot="close">关闭</span>
                   </i-switch>
               </div>
               <Card>
                 <Row>
                     <table  style="text-align: center">
                         <thead>
                         <tr>
                             <th>配置时间段</th>
                             <th style="width: 200px">交易类型</th>
                             <th>返还费率</th>
                         </tr>
                         </thead>
                        <tbody>
                            <tr>
                                <td>
                                    <Input v-model="returnData[0].return_setting_time" size="small" style="width: 100%"  type="text">
                                    <span slot="append">个自然月</span>
                                    </Input>
                                </td>
                                <td>
                                    <span slot="append" style="width: 200px">储蓄卡</span>
                                </td>
                                <td >
                                    <Input v-model="returnData[0].return_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">%</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <Input v-model="returnData[1].return_setting_time" size="small" style="width: 100%"  type="text">
                                    <span slot="append">个自然月</span>
                                    </Input>
                                </td>
                                <td>
                                    <span slot="append" style="width: 200px">信用卡</span>
                                </td>
                                <td>
                                    <Input v-model="returnData[1].return_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">%</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <Input v-model="returnData[2].return_setting_time" size="small" style="width: 100%"  type="text">
                                    <span slot="append">个自然月</span>
                                    </Input>
                                </td>
                                <td>
                                    <span slot="append" style="width: 200px">微信</span>
                                </td>
                                <td>
                                    <Input v-model="returnData[2].return_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">%</span>
                                    </Input>
                                </td>
                            </tr>
                            <tr>
                                <td>
                                    <Input v-model="returnData[3].return_setting_time" size="small" style="width: 100%"  type="text">
                                    <span slot="append">个自然月</span>
                                    </Input>
                                </td>
                                <td>
                                    <span slot="append" style="width: 200px;text-align: center">支付宝</span>

                                </td>
                                <td>
                                    <Input v-model="returnData[3].return_rate" size="small" style="width: 100%"  type="text">
                                    <span slot="append">%</span>
                                    </Input>
                                </td>
                            </tr>
                        </tbody>
                     </table>
                 </Row>
               </Card>
           </div>
        <div class="m-modal-footer">
            <Button type="primary" @click="saveSubmitFn" style="width: 80px">配置保存</Button>
        </div>

    </div>
</template>

<script>
    import API from '../../config/api'
    import qs from 'qs'
    export default {
        props: [ 'rateSettingStatus','dealer_id','test'],
        watch: {
            test(val) {
                this.dealerId=this.dealer_id;
                this.getGradeName()
            }
        },
        data() {
            return {
                displayede:false,
                displayedeReturn:false,
                cycleData:{},
                defaultGradeText:'',
                rateStatus:true,
                switchStatus:true,
                switchReturnStatus:true,
                dealerId:'0',
                dealerRateData:[],
                dataList:[],
                gradeData:[],  //等级数据
                dealer_grade:{
                    dealer_grade_id:'',
                    grade_name:''
                },
                settlement_wayList:[],
                returnData:[] ,   //返回配置数据
                returnSettingData:[]
            }
        },
        methods: {


            //查询结算方式名称
            querySettlement_wayName(i,id){
                if( id =='' || id==undefined){
                    this.dataList[i].close_way='';
                    return;
                }
                this.axios.get(process.env.API_ZSCAR+'/settlement_way/queryOne?settlement_way_id='+id).then(response => {
                    if (response.data.code === 1) {
                        this.dataList[i].close_way=response.data.data.settlement_way_name;
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                }, response => {
                })

            },
            getsettlement_wayName0(data){
                this.querySettlement_wayName(0,data);
            },
            getsettlement_wayName1(data){
                this. querySettlement_wayName(1,data);
            },
            getsettlement_wayName2(data){
                this.querySettlement_wayName(2,data);
            },
            getsettlement_wayName3(data){
                this.querySettlement_wayName(3,data);
            },
            getsettlement_wayName4(data){
                this.querySettlement_wayName(4,data);
            },
            getsettlement_wayName5(data){
                this.querySettlement_wayName(5,data);
            },
            getsettlement_wayName6(data){
                this.querySettlement_wayName(6,data);
            },
            getsettlement_wayName7(data){
                this.querySettlement_wayName(7,data);
            },
           //查询所有结算方式
            querySettlement_way(){
                let  params = qs.stringify( {pageSize: 100,
                    pageNum: 1,
                    status:'1',
                });
                this.axios.get(process.env.API_ZSCAR+'/settlement_way/queryAll?' +params).then(response => {
                    if (response.data.code === 1) {
                  //  console.log(response.data.data.list)
                        this.settlement_wayList=response.data.data.list
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                }, response => {
                })
            },
            //得到等级名称
            getGradeName(){
                this.axios.get( process.env.API_CAR+"/dealer_grade/queryOne?id="+ this.dealer_grade.dealer_grade_id).then(response=>{
                    if (response.data.code === '1') {
                        let res = response.data.data;
                        this.dealer_grade.grade_name=res.grade_name;

                        if(res.is_default_grade==='2'){
                            this.defaultGradeText='--默认等级'
                        }else{
                            this.defaultGradeText=''
                        }

                    } else {
                        vm.$Message.error(response.data.info);
                    }
                }, error=>{

                });
                this.getDealerRateConfig(this.dealerId);
                this.getDefaultReturnSetting(this.dealerId)
            },
            //查询车商等级
            queryGrade(){
                let vm = this ;
                //查询所有数据
                let  params = qs.stringify( {pageSize: 100,
                    pageNum: 1,
                    status:'1'
                });
                this.axios.get( process.env.API_CAR+"/dealer_grade/queryAll?"+ params).then(response=>{
                    if (response.data.code === '1') {
                        let res = response.data.data;
                        let list =  res.list;
                        vm.gradeData = list;
                        if(list.length>0){
                            vm.dealer_grade.dealer_grade_id=list[0].id
                            vm.dealer_grade.grade_name=list[0].grade_name
                        }
                        this.getDealerRateConfig(this.dealerId);
                        this.getDefaultReturnSetting(this.dealerId)

                    } else {
                        vm.$Message.error(response.data.info);
                    }
                }, error=>{

                });
            },
            //查询默认返还配置
            getDefaultReturnSetting(dealerId){
                this.axios.get(process.env.API_ZSCAR + '/return_setting/queryAllCommon?return_dealer_id=' + dealerId+'&return_grade_id='+this.dealer_grade.dealer_grade_id).then(response => {
                    if (response.data.code === 1) {
                        this.returnSettingData = response.data.data;
                       /* console.log("returnSettingData:")
                        console.log(this.returnSettingData)*/
                        if(this.returnSettingData.length == 0){//没有设置收费，调用默认收费配置
                            this.axios.get(process.env.API_ZSCAR + '/return_setting/queryAllCommon?return_dealer_id=0&return_grade_id='+this.dealer_grade.dealer_grade_id).then(response => {
                                if (response.data.code === 1) {
                                    this.displayedeReturn=false;
                                    this.returnSettingData = response.data.data;
                                    this.returnSettingData.forEach(item=>{
                                        item.return_setting_id = '';
                                        item.return_dealer_id=this.dealerId;
                                    });
                                    this.getReturnDataList();
                                } else {
                                    this.$Message.error(response.data.msg);
                                }
                            }, response => {

                            })
                        }else{
                            this.displayedeReturn=true;
                            this.getReturnDataList()
                        }
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                }, response => {
                })
            },
            //查询费率配置
            getDealerRateConfig(dealerId) {
                this.axios.get(API.GET_RATE_CONFIG + '?dealerId=' + dealerId+'&grade_id='+this.dealer_grade.dealer_grade_id).then(response => {
                    if (response.data.code === 1) {
                        this.rateStatus = true;
                        this.dealerRateData = response.data.data;
                        if(this.dealerRateData.length == 0){//没有设置收费，调用默认收费配置
                            this.displayede=false;
                            this.axios.get(API.GET_DEFAULT_RATE_CONFIG+'?grade_id='+this.dealer_grade.dealer_grade_id).then(response => {
                                if (response.data.code === 1) {
                                    this.dealerRateData = response.data.data;
                                    this.dealerRateData.forEach(item=>{
                                        item.id = '';
                                        item.dealer_id=this.dealerId;
                                    });
                                   this.getDataList();
                                } else {
                                    this.$Message.error(response.data.msg);
                                }
                            }, response => {

                            })
                        }else{
                            this.displayede=true;
                            this.getDataList()
                        }


                    } else {
                        this.$Message.error(response.data.msg);
                    }
                }, response => {
                })
            },
            submitFn(){
				if(this.dealerId.match(/,/)){
					this.saveAllRateConfig();
				}else{
					this.saveRateConfig();
				}
            },
            changeRateStatus(){
                this.axios.post(API.CHANGE_RATE_STATUS,qs.stringify({dealerId:this.dealerId,grade_id:this.dealer_grade.dealer_grade_id})).then(response => {
                    if (response.data.code === 1) {
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                }, response => {
                })
            },
            saveSubmitFn(){
            	if(this.dealerId.match(/,/)){
					this.saveAllSetting();
				}else{
					this.saveSetting();
				}
            },
            //保存返回设置
            saveSetting(){
                if(this.dealerId > 0){
                    this.returnData.forEach(item=>{
                        item.return_dealer_id = this.dealerId;
                    })
                }
                this.axios({
                    method:"POST",
                    url:process.env.API_ZSCAR + '/return_setting/saveByList',
                    data:this.returnData,
                    params:{'return_grade_id':this.dealer_grade.dealer_grade_id,'return_grade_name':this.dealer_grade.grade_name}
                }).then(response =>{
                    if (response.data.code === 1) {
                        //this.close();
                        this.returnSettingData=[];
                        this.getGradeName();
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                },response =>{
                });
            },
            //保存所有返回设置
            saveAllSetting(){
            	//this.dealerId
            	
            	if(this.dealerId && this.dealerId!=='0'){
                    this.returnData.forEach(item=>{
                        item.return_dealer_id = '';
                    })
                }
            	
            	this.axios({
                    method:"POST",
                    url:'/zscar-api/return_setting/saveAllByList',
                    data:this.returnData,
                    params:{'dealerIdList':this.dealerId,'return_grade_id':this.dealer_grade.dealer_grade_id,'return_grade_name':this.dealer_grade.grade_name}
                }).then(response =>{
                    if (response.data.code === 1) {
                        //this.close();
                        this.returnSettingData=[];
                        this.getGradeName();
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                },response =>{
                });
            },
            setTipMessage(){
                if(this.dataList[1].start_time==undefined||this.dataList[1].start_time==''){
                    this.$Message.error("储蓄卡：开始时间不能为空！");
                    return;
                }
                if(this.dataList[1].end_time==undefined||this.dataList[1].end_time==''){
                    this.$Message.error("储蓄卡：结束时间不能为空！");
                    return;
                }
                if(Date.parse(this.dataList[1].end_time) / 1000<=(Date.parse(this.dataList[1].start_time) / 1000)){
                    this.$Message.error("储蓄卡：开始时间必须小于结束时间！");
                    return;
                }

                if(this.dataList[3].start_time==undefined||this.dataList[3].start_time==''){
                    this.$Message.error("信用卡：开始时间不能为空！");
                    return;
                }
                if(this.dataList[3].end_time==undefined||this.dataList[3].end_time==''){
                    this.$Message.error("信用卡：结束时间不能为空！");
                    return;
                }
                if(Date.parse(this.dataList[3].end_time) / 1000<=(Date.parse(this.dataList[3].start_time) / 1000)){
                    this.$Message.error("信用卡：开始时间必须小于结束时间！");
                    return;
                }

                if(this.dataList[5].start_time==undefined||this.dataList[5].start_time==''){
                    this.$Message.error("微信：开始时间不能为空！");
                    return;
                }
                if(this.dataList[5].end_time==undefined||this.dataList[5].end_time==''){
                    this.$Message.error("微信：结束时间不能为空！");
                    return;
                }
                if(Date.parse(this.dataList[5].end_time) / 1000<=(Date.parse(this.dataList[5].start_time) / 1000)){
                    this.$Message.error("微信：开始时间必须小于结束时间！");
                    return;
                }

                if(this.dataList[7].start_time==undefined||this.dataList[7].start_time==''){
                    this.$Message.error("支付宝：开始时间不能为空！");
                    return;
                }
                if(this.dataList[7].end_time==undefined||this.dataList[7].end_time==''){
                    this.$Message.error("支付宝：结束时间不能为空！");
                    return;
                }
                if(Date.parse(this.dataList[7].end_time) / 1000<=(Date.parse(this.dataList[7].start_time) / 1000)){
                    this.$Message.error("支付宝：开始时间必须小于结束时间！");
                    return;
                }
            },
            //保存费率配置
            saveRateConfig() {
				this.setTipMessage();

                if(this.dealerId > 0){
                    this.dataList.forEach(item=>{
                        item.dealer_id = this.dealerId;
                    })
                }
                this.axios({
                    method:"POST",
                    url:API.SAVE_RATE_DEALER_CONFIG,
                    data:this.dataList,
                    params:{'grade_id':this.dealer_grade.dealer_grade_id,'grade_name':this.dealer_grade.grade_name}
                }).then(response =>{
                    if (response.data.code === 1) {
                        //this.close();
                        this.dealerRateData=[];
                        this.getGradeName();
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                },response =>{
                });

            },
            saveAllRateConfig(){
            	this.setTipMessage();
            	
            	if(this.dealerId&&this.dealerId!=='0'){
                    this.dataList.forEach(item=>{
                        item.dealer_id = '';
                    })
               }
            	this.axios({
                    method:"POST",
                    url:'/zscar-api/rateControl/allByList',
                    data:this.dataList,
                    params:{'dealerIdList':this.dealerId,'grade_id':this.dealer_grade.dealer_grade_id,'grade_name':this.dealer_grade.grade_name}
                }).then(response =>{
                    if (response.data.code === 1) {
                        //this.close();
                        this.dealerRateData=[];
                        this.getGradeName();
                        this.$Message.success(response.data.msg);
                    } else {
                        this.$Message.error(response.data.msg);
                    }
                },response =>{
                });
            },
            close() {
                this.$emit('closeModal')
            },
            initStartTime1(time){
                this.dataList[1].start_time = time;
                if(Date.parse(time) / 1000>=(Date.parse(this.dataList[1].end_time) / 1000)){
                    this.$Message.error("储蓄卡：开始时间必须小于结束时间");
                }
            },
            initEndTime1(time){
                this.dataList[1].end_time = time;
                if(Date.parse(time) / 1000<=(Date.parse(this.dataList[1].start_time) / 1000)){
                    this.$Message.error("储蓄卡：开始时间必须小于结束时间");
                }

            },
            initStartTime2(time){
                this.dataList[3].start_time = time;
                if(Date.parse(time) / 1000>=(Date.parse(this.dataList[3].end_time) / 1000)){
                    this.$Message.error("信用卡：开始时间必须小于结束时间");
                }
            },
            initEndTime2(time){
                this.dataList[3].end_time = time;
                if(Date.parse(time) / 1000<=(Date.parse(this.dataList[3].start_time) / 1000)){
                    this.$Message.error("信用卡：开始时间必须小于结束时间");
                }
            },
            initStartTime3(time){
                this.dataList[5].start_time = time;
                if(Date.parse(time) / 1000>=(Date.parse(this.dataList[5].end_time) / 1000)){
                    this.$Message.error("微信：开始时间必须小于结束时间");
                }
            },
            initEndTime3(time){
                this.dataList[5].end_time = time;
                if(Date.parse(time) / 1000<=(Date.parse(this.dataList[5].start_time) / 1000)){
                    this.$Message.error("微信：开始时间必须小于结束时间");
                }
            },
            initStartTime4(time){
                this.dataList[7].start_time = time;
                if(Date.parse(time) / 1000>=(Date.parse(this.dataList[7].end_time) / 1000)){
                    this.$Message.error("支付宝：开始时间必须小于结束时间");
                }
            },
            initEndTime4(time){
                this.dataList[7].end_time = time;
                if(Date.parse(time) / 1000<=(Date.parse(this.dataList[7].start_time) / 1000)){
                    this.$Message.error("支付宝：开始时间必须小于结束时间");
                }
            },
            //改变返还状态
            changeReturnStatus(data){
                if(data==true){
                    this.returnData.map((item)=>{
                        item.status='1'
                    })

                }else{
                    this.returnData.map((item)=>{
                        item.status='2'
                    })
                }
                this.saveSetting();

    },
            //数据初始化
            getReturnDataList(){
                let vm = this;
                let localArray = [];
                if(this.returnSettingData.length ==4){
                    this.returnSettingData.map((item)=>{
                        if(item.return_trade_type=='1'){//  1:储蓄卡
                            localArray[0] = item ;
                        }else if(item.return_trade_type=='0'){//0：信用卡
                            localArray[1] = item ;
                        }else if(item.return_trade_type=='2'){//2:微信
                            localArray[2] = item ;
                        }else if(item.return_trade_type=='3'){//3支付宝
                            localArray[3] = item ;
                        }
                    })
                }else{
                    localArray = [
                        {
                            return_setting_time:'',
                            return_trade_type:'1',
                            return_dealer_id:vm.dealerId,
                            return_rate:'',
                            status:'1'
                        },
                        {
                            return_setting_time:'',
                            return_trade_type:'0',
                            return_dealer_id:vm.dealerId,
                            return_rate:'',
                            status:'1'
                        },
                        {
                            return_setting_time:'',
                            return_trade_type:'2',
                            return_dealer_id:vm.dealerId,
                            return_rate:'',
                            status:'1'
                        },
                        {
                            return_setting_time:'',
                            return_trade_type:'3',
                            return_dealer_id:vm.dealerId,
                            return_rate:'',
                            status:'1'
                        },
                    ]
                }
                vm.switchReturnStatus = this.returnSettingData.some((item)=>{
                    return item.status == 1;
                })
                this.returnData=localArray;
            },
            getDataList(){
                let vm = this;
                let localArray = [];
                if(this.dealerRateData.length ==8){
                    this.dealerRateData.map((item)=>{
                        if(item.card_class==1){
                            item.config_item=='default' ? localArray[0] = item : localArray[1] = item;
                        }else if(item.card_class==0){
                            item.config_item=='default' ? localArray[2] = item : localArray[3] = item;
                        }else if(item.card_class==2){
                            item.config_item=='default' ? localArray[4] = item : localArray[5] = item;
                        }else if(item.card_class==3){
                            item.config_item=='default' ? localArray[6] = item : localArray[7] = item;
                        }
                    })
                    vm.switchStatus = this.dealerRateData.some((item)=>{
                        return item.status == 1;
                    })
                }else if(this.dealerRateData.length ==4){
                    this.dealerRateData.map((item)=>{
                        if(item.card_class==1){
                            item.config_item=='default' ? localArray[0] = item : localArray[1] = item;
                        }else if(item.card_class==0){
                            item.config_item=='default' ? localArray[2] = item : localArray[3] = item;
                        }
                    })
                    vm.switchStatus = this.dealerRateData.some((item)=>{
                        return item.status == 1;
                    })
                }else {
                    localArray = [
                        {
                            dealer_id:vm.dealerId,
                            card_class:1,
                            config_item:'default',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },
                        {
                            dealer_id:vm.dealerId,
                            card_class:1,
                            config_item:'time_range',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },{
                            dealer_id:vm.dealerId,
                            card_class:0,
                            config_item:'default',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },
                        {
                            dealer_id:vm.dealerId,
                            card_class:0,
                            config_item:'time_range',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },{
                            dealer_id:vm.dealerId,
                            card_class:2,
                            config_item:'default',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },
                        {
                            dealer_id:vm.dealerId,
                            card_class:2,
                            config_item:'time_range',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },{
                            dealer_id:vm.dealerId,
                            card_class:3,
                            config_item:'default',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        },
                        {
                            dealer_id:vm.dealerId,
                            card_class:3,
                            config_item:'time_range',
                            close_id:'',
                            close_way:'',
                            close_rate:'',
                            start_time:'',
                            end_time:'',
                            max_money:'0',
                            status:1
                        }
                    ]
                }
               // return localArray
                this.dataList=localArray;
            }

        },
        created(){
            this.querySettlement_way()

            this.queryGrade();

            //jiazai 模板
            this.getDataList()
            this.getReturnDataList()

        },
       /* computed: {
            dataList () {

            }
        }*/
    }
</script>
<style scoped  >
    .m-modal-cov {
        position: fixed;
        width: 100%;
        height: 100%;
        background-color: #000;
        z-index: 101;
        top: 0;
        left: 0;
        opacity: .5;
    }
    .m-modal-box {
        position: fixed;
        width: 800px;
        z-index: 102;
        margin-left: 10%;
        background-color: #fff;
        border-radius: 5px;
    }
    .m-modal-content {
        padding: 20px;
    }
    .m-modal-header {
        height: 40px;
        line-height: 40px;
        font-size: 14px;
        border-bottom: 1px solid #d6d6d6;
        padding: 0 10px 0 20px;
    }
    .m-modal-header span {
        float: right;
        padding: 0 10px;
        cursor: pointer;
    }
    .m-modal-footer {
        height: 50px;
        line-height: 50px;
        border-top:1px solid #d6d6d6;
        padding-right: 20px;
        text-align: right;
    }
    .m-modal-content-header {
        height: 40px;
    }
    .api table {
        font-family: Consolas,Menlo,Courier,monospace;
        font-size: 12px;
        border-collapse: collapse;
        border-spacing: 0;
        empty-cells: show;
        border: 1px solid #e9e9e9;
        width: 100%;
        margin-bottom: 24px;
    }
    .api table td, .api table th {
        border: 1px solid #e9e9e9;
        padding: 8px 16px;
        text-align: left;
        width: auto;
    }
    .api table th {
        background: #f7f7f7;
        white-space: nowrap;
        color: #5c6b77;
        font-weight: 600;
    }
    .car-header {
        background-color: #f7f7f7;
        padding-left: 15px;
        border: 1px solid #e9eaec;
        border-radius: 2px;
        height: 30px;
        line-height: 30px;
    }


    .m-detail-modal {
        width: 100%;
        height: 100%;
        position: absolute;
        top: 0;
        left: 0;
        background-color: #fff;
        z-index: 100;
    }
    .header {
        background-color: #f8f8f9;
        height: 45px;
        line-height: 45px;
        font-size: 16px;
        padding-left: 25px;
        padding-right: 5px;
        color: #000;
        box-shadow: 1px 1px 1px rgba(220, 172, 172, .5);
    }
   .header   span {
        float: right;
        padding: 0 20px;
        cursor: pointer;
    }


     .content {
        font-size: 14px;
        padding: 15px;
        overflow-y: auto;
    }

    .list-header {
        height: 45px;
        color: #333;
        line-height: 45px;
    }

    .list-row {
        padding-left: 100px;
        font-size: 14px;
        line-height: 40px;
    }
    .list-row img {
        width: 100px;
        height: auto;
    }
    .car-header {
        background-color: #f7f7f7;
        padding-left: 15px;
        border: 1px solid #e9eaec;
        border-radius: 2px;
    }

	table{
		width: 100%;
	}
	table button{
		margin: 0 20px;
	}
</style>

